﻿package view.components.mainMenu 
{
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import org.casalib.display.CasaMovieClip;
	import flash.events.MouseEvent;
	import gs.TweenLite;
	import gs.easing.Circ;
	import org.casalib.util.NavigateUtil;
	import view.components.utils.UIEvent;
	
	
	/**
	 * ...
	 * @author Lobanov
	 */
	public class MenuItem extends CasaMovieClip
	{
		public static var DEEPLINK_INFO:String = "inforfation of target click handler";
		
		public var maska:MovieClip;
		public var maskaSecond:MovieClip;
		public var linkArea:MovieClip;
		
		public var normalText:TextField;
		public var italiclText:TextField;
		
		private static const __MASK2_X:Number = 32.0;
		private static const __MASK1_X:Number = -66.9;
		
		private static const __ANGULAR_WIDTH:Number = 37.0;
		private var _targetModule:String;
		
		public function MenuItem($title:String = "", $route:String = "", $mod = "") 
		{			
			normalText.text = italiclText.text = $title;
			normalText.autoSize = italiclText.autoSize = TextFieldAutoSize.LEFT;
			
			_targetModule = $mod;
			
			var maxWidth:int = Math.max(normalText.width, italiclText.width);
			linkArea.width = maxWidth;
			
			linkArea.alpha = 0;
			linkArea.buttonMode = true;
			
			linkArea.addEventListener(MouseEvent.CLICK, clickHandle);
			linkArea.addEventListener(MouseEvent.ROLL_OVER, overHandle);
			linkArea.addEventListener(MouseEvent.ROLL_OUT, outHandle);
			
			/**
			 * EVENTS
			 */
			function overHandle(e:MouseEvent):void {
				TweenLite.to( maska, 1 , { x:__MASK1_X + maxWidth + __ANGULAR_WIDTH, ease:Circ.easeOut } );
				TweenLite.to( maskaSecond, 1 , { x:__MASK2_X + maxWidth + __ANGULAR_WIDTH, ease:Circ.easeOut } );
			}
			
			function outHandle(e:MouseEvent):void {
				TweenLite.to( maska, 1 , { x:__MASK1_X, ease:Circ.easeOut} );
				TweenLite.to( maskaSecond, 1 , { x:__MASK2_X, ease:Circ.easeOut} );
			}
			
			function clickHandle(e:MouseEvent):void {
				dispatchEvent(new UIEvent( DEEPLINK_INFO, [$route, $mod] ));
			}
		}
		
		public function get menuWidth():Number {
			return linkArea.width;
		}
		
		public function get nameModule():String {
			return _targetModule;
		}
		
	}

}